package string;

/**
 * int indexOf(String s)
 * 检索给定字符串(s)在当前字符串中第一次出现的位置
 * int
 */

public class IndexOfDemo {
    public static void main(String[] args) {
        String str="thinking in java";
        //第一次出现in
        int index=str.indexOf("in");
        System.out.println(index);


        index=str.indexOf("in",4);
        System.out.println(index);
        //是否出现asd
        index= str.indexOf("asd");
        System.out.println(index);
        //最后一次出现in
        index =str.lastIndexOf("in");
        System.out.println(index);



        String str1="thinking in java";
        int index1=str1.indexOf("n");
        System.out.println(index1);

        index1=str1.indexOf("n",4);
        System.out.println(index1);

        index1=str1.indexOf("com");
        System.out.println(index1);

        index1=str1.lastIndexOf("n");
        System.out.println(index1);
    }
}
